const pt = require('puppeteer');
const process = require('process');

module.exports = async function (options) {
  //参数列表 optoins callback url
  const bs = await pt.launch(),
        pg = await bs.newPage(),
        url = options.url;
  //配置
  await pg.goto(url, {
    timeOut: 30 * 1000,
    waitUtil: 'newworkidle2'
  });

  const result = await pg.evaluate(options.callback);

  await process.send(result); //发送数据给子进程

  //关闭浏览器
  await bs.close();

  setTimeout(()=> {
    process.exit(0);
  }, 1000);
}